package com.code.origin.utils.other;

import java.io.PrintWriter;
import java.io.StringWriter;

public class BaseUtils {

    /**
     * 获取e.printStackTrace() 的具体信息，赋值给String 变量，并返回
     * @param e Exception
     * @return String e.printStackTrace() 中 的信息
     * @author: Huangds
     * @date: 2020-12-23 15:01
     * @version: v1.0
     */
    public static String getStackTraceInfo(Exception e) {
        StringWriter sw = null;
        PrintWriter pw = null;
        try {
            sw = new StringWriter();
            pw = new PrintWriter(sw);
            /**将出错的栈信息输出到printWriter中*/
            e.printStackTrace(pw);
            pw.flush();
            return sw.toString();
        } catch (Exception ex) {
            return "printStackTrace()转换错误";
        } finally {
            if (pw != null) {
                pw.close();
            }
        }
    }
}
